package br.fatec.ads.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.fatec.ads.dao.UsuarioDAO;
import br.fatec.ads.exception.DataBaseException;
import br.fatec.ads.exception.UsuarioException;
import br.fatec.ads.model.Usuario;

/**
 * Servlet implementation class ConsultaUsuario
 */
public class UsuarioConsultar extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   public UsuarioConsultar() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(false);
		
		Usuario usu = new Usuario();
		UsuarioDAO usuDAO = new UsuarioDAO();
		
		try {
			usu = usuDAO.consultarUsuario(Integer.parseInt(request.getParameter("idUsuarioConsultar")));
		} catch (UsuarioException e) {
			e.printStackTrace();
		} catch (DataBaseException e) {
			e.printStackTrace();
		}
		
        session.setAttribute("usuario", usu);
		
		request.getRequestDispatcher("cadusuario_c.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
